class TFShroud extends TFPowerups;

var float lastsound;

replication
{
    reliable if( Role==ROLE_Authority )
	lastsound;
}

state Activated
{
	function BeginState()
	{
//		local int i;

        initialstate='activated';
        if(instigator==none) instigator=pawn(owner);
        Owner.PlaySound(ActivateSound,SLOT_Interface,3);

        /*xpawn(Instigator).visibility=0;

        for ( i=0; i<Clamp(xpawn(Instigator).Skins.Length,2,4); i++ )
		{
			xpawn(Instigator).Skins[i]=FinalBlend'TFMedia.TFShroud';
		}*/

        xpawn(owner).SetInvisibility(999999);
        TFPawn(owner).antiprotector = true;

        bActive = true;
        settimer(0.05, true);
	}

    function Timer()
    {
        local float factor;
//        local xemitter fx;

        if(instigator==none || instigator.Health<=0) gotostate('');

        factor=vsize(instigator.Velocity)/instigator.GroundSpeed;

        //if(instigator.Weapon.FireMode[0].bIsFiring || instigator.Weapon.FireMode[1].bIsFiring)
        //    factor+=0.5+frand()/2;

        if(vsize(instigator.Velocity) < 240)
        {
            xpawn(owner).SetInvisibility(999999);
            TFPawn(owner).antiprotector=true;
        }
        else
        {
            TFPawn(owner).antiprotector=false;
        }

        xpawn(owner).ambientglow=fmin(254,factor*254);
        if(xpawn(owner).weapon!=none)
            xpawn(owner).weapon.ambientglow=xpawn(owner).ambientglow;

        if(frand()*15<factor && level.timeseconds>lastsound+0.1)
        {
            lastsound=level.timeseconds;
            Owner.PlaySound(sound'TFMedia.TFShroudGlitch',SLOT_None,factor/6,,, 0.7+frand()*0.6);
        }
    }

	function EndState()
	{
        if(xpawn(owner)!=none)
        {
            xpawn(owner).SetInvisibility(0);
            TFPawn(owner).antiprotector = false;
            xpawn(owner).ambientglow=xpawn(owner).default.ambientglow;
            if(xpawn(owner).weapon!=none)
            xpawn(owner).weapon.ambientglow=xpawn(owner).weapon.default.ambientglow;
        }
        bActive = false;
	}

}

defaultproperties
{
     bAutoActivate=True
     bActivatable=True
     ActivateSound=Sound'TFMedia.Equipment.TFShroudActivate'
     bReplicateInstigator=True
     SkillCost=500
}
